﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JSON;
using Facebook_Graph_Toolkit.FacebookObjects;

namespace Facebook_Graph_Toolkit.GraphApi {
    /// <summary>
    /// An application registered on Facebook Platform
    /// </summary>
    [Serializable]
    public class Application : GraphApiObject{
        /// <summary>
        /// Gets the information of a Facebook Application
        /// </summary>
        /// <param name="ApplicationID">Application ID</param>
        public Application(string ApplicationID) : base(Helpers.WebResponseHelper.GetJsonFromFacebookObject(ApplicationID, "")){
        }

        #region public properties
        /// <summary>
        /// The application ID
        /// </summary>
        public string ID { get { return (string)data["id"]; } }
        /// <summary>
        /// The title of the application
        /// </summary>
        public string Name { get { return (string)data["name"]; } }
        /// <summary>
        /// The description of the application written by the 3rd party developers
        /// </summary>
        public string Description { get { return (string)data["description"]; } }
        /// <summary>
        /// The category of the application
        /// </summary>
        public string Category { get { return (string)data["category"]; } }
        /// <summary>
        /// A link to the application's Page on Facebook
        /// </summary>
        public string AppPageUrl { get { return (string)data["link"]; } }
        /// <summary>
        /// The Canvas Name of the application
        /// </summary>
        public string CanvasName { get { return (string)data["canvas_name"]; } }
        #endregion

        /// <summary>
        /// Get all the posts on the application's wall by the application itself, specified by the Application ID
        /// </summary>
        /// <param name="ApplicationID">Application ID</param>
        /// <param name="AccessToken">Access Token</param>
        /// <param name="Limit">Maximum number of posts returned</param>
        /// <param name="Offset">Number of posts to offset before returning the first post</param>
        /// <returns>The application's own posts</returns>
        static public IList<Post> GetPosts(string ApplicationID, string AccessToken, int? Offset, int? Limit) {
            return Helpers.ApiCaller.GetPosts(ApplicationID, AccessToken, Offset, Limit);
        }

        /// <summary>
        /// Get all posts on the wall of the application specified by the Application ID
        /// </summary>
        /// <param name="ApplicationID">The application's wall</param>
        /// <param name="AccessToken">Access Token</param>
        /// <param name="Limit">Maximum number of posts returned</param>
        /// <param name="Offset">Number of posts to offset before returning the first post</param>
        /// <returns>The application's wall</returns>
        static public IList<Post> GetFeed(string ApplicationID, string AccessToken, int? Offset, int? Limit) {
            return Helpers.ApiCaller.GetFeed(ApplicationID, AccessToken, Offset, Limit);
        }
     
        /// <summary>
        /// Gets the photo albums created by the application specified by the Application ID
        /// </summary>
        /// <param name="ApplicationID">Application ID</param>
        /// <param name="Limit">Maximum number of albums returned</param>
        /// <param name="Offset">Number of albums to offset before returning the first album</param>
        /// <returns>The photo albums this application created</returns>
        static public IList<Album> GetAlbums(string ApplicationID,int? Offset, int? Limit) {
            return Helpers.ApiCaller.GetAlbums(ApplicationID, "", Offset, Limit);
        }

        /// <summary>
        /// Gets the Reviews of this Application
        /// </summary>
        /// <param name="ApplicationID">Application ID</param>
        /// <param name="Offset">Number of Reviews to offset before returning the first Review</param>
        /// <param name="Limit">Maximum number of Reviews returned</param>
        /// <returns></returns>
        public static IList<AppReview> GetReviews(string ApplicationID, int? Offset, int? Limit) {
            return Helpers.ApiCaller.GetAppReviews(ApplicationID,Offset,Limit);
        }
    }
}
